home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: johnb@pivotal-dm.ccmail.compuserve.com (John Bain)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: Integral promotion problem
- Date: 13 Mar 1996 06:40:50 -0600
- Organization: Pivotal Technologies Ltd.
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4i6foi$p2p@solutions.solon.com>
- References: <31404525.26295649@dub-news-svc-3.compuserve.com> <314405dd.13127805@dub-news-svc-3.compuserve.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: Forte Agent .99d/32.182
-
- I wrote:
-
- >The reference section of K&R2 (the best
- >definition I have, as I do not have a copy of the standard) says, in its
- >definition of '~' (A7.4.6):
- >
- >"The integral promotions are performed. If the operand is unsigned, the
- >result is computed by subtracting the value from the largest value of
- >the promoted type. If the operand is signed, the result is computed by
- >converting the promoted operand to the corresponding unsigned type,
- >applying ~, and converting it back to the unsigned type."
- >
- >I didn't believe that the implementation defined unsigned->signed
- >conversions were happening, but I didn't believe the results I was
- >seeing either!
- >
- >Incidentally, I assume that when it says "if the operand is unsigned" it
- >means _before_ promotion?
-
- I have no idea what I was thinking about when I wrote this.
-
- It seems to me that it must mean _after_ promotion, and is likely to
- result in an implementation defined value whenever ~ is applied to an
- unsigned short on an implementation where unsigned shorts promote to
- ints.
-
- I.e. (assuming a is unsigned short) in evaluating ~a, a is first
- promoted to int (well defined), the int value is converted to unsigned
- int (well defined), ~ is applied to the unsigned value (well defined),
- and the unsigned result is converted back to int (implementation
- defined, if, as seems likely, the value of the unsigned int result
- cannot be represented in an int.)
-
- Is this interpretation correct?
-
- Cheers,
-
- John
- -----------------------------------------------------------------
- John Bain
- johnb@pivotal-dm.ccmail.compuserve.com
- -----------------------------------------------------------------
-